package com.taotao.job.core.executor;

import com.alibaba.fastjson.JSON;
import com.taotao.job.core.enums.RunStatus;
import lombok.Getter;

/**
 * 运行结果
 *
 * @author fanbeibei
 * @version 1.0
 * @date 2021/2/4 14:40
 */
@Getter
public class RunResult {

    /**
     * 运行状态
     */
    private Integer runStatus;
    /**
     * 说明
     */
    private String msg;
    /**
     * execute方法返回值
     */
    private ExecuteReturn executeReturn;
    /**
     * 运行上下文
     */
    private ExecutorContext executorContext;

    private RunResult(Integer runStatus,String msg, ExecuteReturn executeReturn, ExecutorContext executorContext) {
        this.runStatus = runStatus;
        this.msg = msg;
        this.executeReturn = executeReturn;
        this.executorContext = executorContext;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }


    public static RunResult successResult(String msg, ExecuteReturn executeReturn, ExecutorContext executorContext){
        return new RunResult(RunStatus.SUCCESS.getCode(),msg,executeReturn,executorContext);
    }

    public static RunResult failResult(String msg, ExecuteReturn executeReturn, ExecutorContext executorContext){
        return new RunResult(RunStatus.FAIL.getCode(),msg,executeReturn,executorContext);
    }


}
